package ucam.acciones;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.tiles.AttributeContext;
import org.apache.tiles.TilesContainer;
import org.apache.tiles.servlet.context.ServletUtil;

public abstract class Accion {

	private String definition = "myapp.homepage";
	
	protected abstract void doAttributeContext(AttributeContext attributeContext);
	public abstract void execute(HttpServletRequest req, HttpServletResponse resp);
	
	protected void renderPage(HttpServletRequest req, HttpServletResponse resp){
		TilesContainer container = ServletUtil.getContainer(
		        req.getSession().getServletContext());
		AttributeContext attributeContext = container.startContext(req,resp);
		
		this.doAttributeContext(attributeContext);
		
		container.render(this.definition, req, resp);
		container.endContext(req, resp);
	}
	
	public void setDefinition(String definition){
		this.definition = definition;
	}
	
}
